import serial
import time
import _thread  # 导入线程包

#data_ser = serial.Serial("COM21",115200,timeout = 5)
data_ser = serial.Serial("/dev/ttyUSB0",115200,timeout = 5)
data_ser.flushInput()


serial_read=""


def get_data():
  global serial_read
  while True:
    
    data_count = data_ser.inWaiting()
    if data_count !=0 :
      recv = data_ser.readline(data_ser.in_waiting).decode("utf-8")
      #print(time.time()," data_recv --> ", recv)
      #print("rec:",recv)
      serial_read=recv.strip().split(',') 
      if (len(serial_read)==6):
        #print(serial_read)
        print(float(serial_read[0]),float(serial_read[1]),float(serial_read[2]),float(serial_read[3]),float(serial_read[4]),float(serial_read[5]))
    time.sleep(0.1)


if __name__ == '__main__':
  
  _thread.start_new_thread(get_data,()) # 开启线程，执行get_data方法
  while 1:
    time.sleep(1) 
    #data_ser.write('hello '.encode("utf-8"))
    #time.sleep(1)
    #data_ser.write('world\r\n'.encode("utf-8")) # 发送二进制0
    #print('send..')